<?php
class CategoryModel
{
    public function __construct()
    {
        $this->db   = Yaf_Registry::get('db');
        $this->time = date("Y-m-d H:i:s",time());
    }
    
    /*public function selectCategory($start,$everyPage){
        $sql = "select * from `category` limit {$start},{$everyPage}";
        return $this->db->query($sql);
    }*/

    public function getCategoryInfo(){
        $sql = "select * from `category_xxcy` ";
        return $this->db->query($sql);
    }

    public function getAllCount()
    {
        $sql="select count(*) as `rows` from `category_xxcy` ";
        return $this->db->query($sql);
    }

    public function getCategoryChildInfo($id){
        $sql = "select  * from `category_xxcy`  where catid={$id}";
        return $this->db->query($sql);
    }
    
    public function del($id) 
    {
        $sql = "delete from `category_xxcy` where catid='{$id}' ";
        return $this->db->query($sql);
    }

    public function add($info) 
    {
        $sql = "insert into `category_xxcy`(`catname`,`siteid`,`create_time`) values('{$info['catname']}','{$info["siteid"]}',UNIX_TIMESTAMP('{$this->time}'))";
        return $this->db->query($sql);
    }

    public function edit($info, $id) 
    {
        $sql = "update `category_xxcy` set `name`='{$info['catname']}', `siteid`='{$info['siteid']}',`create_time`=UNIX_TIMESTAMP('{$this->time}') WHERE catid='{$id}'";
        return $this->db->query($sql);
    }

    public function getNameById($id){
        $sql = "select * from `category_xxcy` where siteid='{$id}'";
        return $this->db->query($sql);
    }
    
    public function getNamesById($id){
        $sql = "select * from `category_dzsw` ";
        return $this->db->query($sql);
    }
}
?>